package indi.zhifa.engine.test;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import indi.zhifa.engine.core.common.entity.mpe.BaseEntity;
import indi.zhifa.engine.mpenhance.service.IZfDbService;
import indi.zhifa.engine.mpenhance.service.impl.ZfDbServiceImpl;

public class DAOGen {
    public static void main(String[] args) {
        String outputPath =  "E:\\DOCUMENT\\generator\\auth";
        String domainName = "Auth";
        String prefix = "Gen";
        FastAutoGenerator.create("jdbc:mysql://192.168.0.64/auth?useSSL=false&useUnicode=true&characterEncoding=utf-8",
                        "dbMgr", "qqhilvMgAl@7")
                .globalConfig(builder -> {
                    // 设置作者
                    builder.author("织法")
                            // 开启 swagger 模式
                            .enableSwagger()
                            // 指定输出目录
                            .outputDir(outputPath);
                })
                .packageConfig(builder -> {
                    // 设置父包名
                    builder.parent("indi.zhifa.test")
                            // 指定模块名称
                            .moduleName("dao")
                            .entity("po")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper");
                })
                .strategyConfig(builder -> {
                    // 设置过滤表前缀

                    builder.addInclude("user")
                            .entityBuilder()
                            .enableLombok()
                            .enableRemoveIsPrefix()
                            .enableFileOverride()
                            .logicDeleteColumnName("del")
                            .logicDeletePropertyName("del")
                            .idType(IdType.ASSIGN_ID)
                            .formatFileName(prefix+"%sEntity")
                            .superClass(BaseEntity.class)
                            .disableSerialVersionUID()
                            .javaTemplate("templates/MyEntity.java")
                            .versionColumnName("version")
                            .versionPropertyName("version")
                            .addSuperEntityColumns("id","create_time","create_id","create_name","modify_id","modify_time","modify_name","version","del")
                            .serviceBuilder()
                            .formatServiceFileName("I"+prefix+"%sDbService")
                            .formatServiceImplFileName(prefix+"%sDbServiceImpl")
                            .superServiceClass(IZfDbService.class)
                            .superServiceImplClass(ZfDbServiceImpl.class)
                            .serviceImplTemplate("templates/MyServiceImpl.java")
                            .serviceTemplate("templates/MyService.java")
                            .mapperBuilder()
                            .formatMapperFileName(prefix+"%sMapper")
                            .mapperTemplate("templates/MyMapper.java")
                            .disableMapperXml()
                            .controllerBuilder()
                            .disable();
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
